package com.itcast.yygh.hosp.controller;

import com.itcast.common.result.R;
import com.itcast.yygh.hosp.service.DepartmentService;
import com.itcast.yygh.hosp.service.HospitalService;
import com.itcast.yygh.hosp.service.ScheduleService;
import com.itcast.yygh.model.model.hosp.Hospital;
import com.itcast.yygh.model.model.hosp.Schedule;
import com.itcast.yygh.model.vo.hosp.DepartmentVo;
import com.itcast.yygh.model.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 医疗-用户系统首页医院数据
 */
@Api("预约平台医院数据")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {
    //引入service的依赖
    @Resource
    private HospitalService hospitalService;
    //引入科室的service
    @Resource
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    //医院数据分页查询
    @ApiOperation("医院数据分页查询")
    @GetMapping("/findPage/{page}/{limit}")
    public R findPage(@PathVariable Integer page , @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo){
        //调用service查询数据的分页
        Page<Hospital> pages = hospitalService.findPage(page,limit,hospitalQueryVo);
        //返回对应结果
        return R.ok().data("pages",pages);
    }
    //根据医院名称查询医院数据
    @ApiOperation("根据医院名称查询医院数据")
    @GetMapping("/findByHosname/{hosname}")
    public R findByHosname(@PathVariable String hosname){
        List<Hospital> hospitals = hospitalService.findByHosname(hosname);
        return R.ok().data("list",hospitals);
    }
    //查询医院对应的科室列表
    @ApiOperation("查询科室列表")
    @GetMapping("/findDepart/{hoscode}")
    public R findDepart(@PathVariable String hoscode){
        List<DepartmentVo> deptList = departmentService.getDeptList(hoscode);
        return R.ok().data("list",deptList);
    }
    //查询医院详情数据
    @ApiOperation("查询医院详情数据")
    @GetMapping("/findHospDetail/{hoscode}")
    public R findHospDetail(@PathVariable String hoscode){
        Map<String,Object> map = hospitalService.findHospDetail(hoscode);
        return R.ok().data(map);
    }
    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public R getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {

        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return R.ok().data(map);
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public R findScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        List<Schedule> scheduleList = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
        return R.ok().data("scheduleList",scheduleList);
    }
    @ApiOperation(value = "获取排班详情")
    @GetMapping("getSchedule/{id}")
    public R getScheduleList(
            @PathVariable String id) {
        Schedule schedule = scheduleService.getById(id);
        return R.ok().data("schedule",schedule);
    }
}
